package com.cyh.pangu.offer;

public class Offer56_2 {

    public int singleNumber(int[] nums) {

        int[] result = new int[32];
        for (int num : nums) {
            int flag = 1;
            for (int i = 0; i < 32; i++) {
                int tempR = num & flag;
                if (tempR != 0) {
                    result[i]=result[i]+1;
                }
                flag = flag<<1;
            }
        }

        int res = 0;
        for (int i = 31; i >=0; i--) {
            int tempR = result[i] % 3;
            res = res<<1;
            res = res + tempR;
        }

        return res;
    }

    public static void main(String[] args) {
        Offer56_2 offer56_2 = new Offer56_2();
        int[] nums = new int[]{2,2,2,3};
        int num = offer56_2.singleNumber(nums);
        System.out.printf("num:" + num);
    }
}
